package com.zyht.common.util;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * 描述：基于java8的日历工具<br>
 * 作者：ZRB <br>
 * 修改日期：2017年6月22日下午3:56:15 <br>
 */
public class NCalendarUtil {

	public static final LocalDateTime date2LocalDateTime(Date date) {
		Instant instant = date.toInstant();
		ZoneId zoneId = ZoneId.systemDefault();
		return LocalDateTime.ofInstant(instant, zoneId);
	}

	public static final LocalDate date2LocalDate(Date date) {
		return date2LocalDateTime(date).toLocalDate();
	}

	public static final LocalTime date2LocalTime(Date date) {
		return date2LocalDateTime(date).toLocalTime();
	}

	public static final Date localDateTime2Date(LocalDateTime localDateTime) {
		ZoneId zone = ZoneId.systemDefault();
		Instant instant = localDateTime.atZone(zone).toInstant();
		return Date.from(instant);
	}

	public static final Date localDate2Date(LocalDate localDate) {
		ZoneId zone = ZoneId.systemDefault();
		Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
		return Date.from(instant);
	}

	public static final Date localDateAndLocalTime2Date(LocalDate localDate, LocalTime localTime) {
		LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
		return localDateTime2Date(localDateTime);
	}
}
